<?php include('header.php'); ?>
<style type="text/css">

    ul.showInColumn {
        display: block;
        float: left;
        list-style: none;
        padding: 0px;
        margin: auto;
        width: 100%;
        border: 0px dotted #333333; /* เทียบใกล้เคียงกับการกำหนด  ของ table  */
    }

    ul.showInColumn li {
        list-style: none;
        display: block;
        float: left;
        margin: 5px; /* เทียบใกล้เคียงกับการกำหนด  cellspacing"  ของ table  */
        margin-left: 3px;
        border: 1px solid #333333;
        padding: 10px; /* เทียบใกล้เคียงกับการกำหนด  cellpadding  ของ table  */
        /* เทียบใกล้เคียงกับการกำหนด border ใน td ของ table  */
        width: 170px; /*  กำหนดความกว้างของแต่ละคอลัมน์  */
        height: 70px;
        word-wrap: break-word;

    }

    li.nReservation {
        background-color: #99CC99;	
    }

    li.rReservation {
        background-color: #FFFF66;
    }

    li.rReservation1 {
        background-color: #FF9933;
    }

    li.rReservation2 {
        background-color: #FF0000;
    }

    li.overmouse{
        background-color: #1BE059;
        cursor:pointer;
    }

    .clr {
        clear: both;
        float: none;
        height: 0;
        line-height: 0; /* fix ie */
        font-size: 0; /* fix ie */
        display: block; /* กรณีเอาใส่กับ tag อื่นที่ไม่ใช่ div หรือ p */
    }
</style>

<body>
    <?php
    $time = time();
    $d = date("H", $time);

    if ($d <= '6') {
        $ddate = strtotime("-1 day", $time);
        $day = date("Y-m-d", $ddate);
    } else {
        $day = date("Y-m-d", $time);
    }

    $Date = ThaiDate(strtotime($day));
    ?>
    <form name="frmMain"  id="frmMain" method="post" action="checkin_select.php">
        <div class="box">
            <div class="left"></div>
            <div class="right"></div>
            <div class="heading"><h1>Check In ห้องพัก <?php echo $Date; ?></h1>
                <div class="buttons">
                    <a class="button" onclick="return check(frmMain);"><span>Check In</span></a>
                </div></div>
            <div class="content" align="center">

                <ul class="showInColumn">
                    <?php
                    $rQuery = mysql_query("SELECT room_id,room_name FROM room ORDER BY room_name");
                    while ($rRow = mysql_fetch_array($rQuery)) {
                        $roomid = $rRow['room_id'];
                        $sQuery = mysql_query("SELECT reservation.room_id as room_id,reservation.reservation_status as reservation_status,reservation_detail.reservation_detail_id as reservation_detail_id,reservation_detail.reservation_detail_fname as reservation_detail_fname,reservation_detail.reservation_detail_lname as reservation_detail_lname,reservation_detail.reservation_detail_phone as reservation_detail_phone FROM reservation,reservation_detail WHERE reservation.reservation_detail_id = reservation_detail.reservation_detail_id AND room_id = '" . $rRow['room_id'] . "' AND reservation_checkin = '$day' ");
                        $sRow = mysql_fetch_array($sQuery);
                        if ($sRow) {
                            $rDetailID = $sRow['reservation_detail_id'];
                            if ($sRow['reservation_detail_phone'] != "" && $sRow['reservation_detail_phone'] != '-') {
                                $phone = "โทร." . $sRow['reservation_detail_phone'];
                            }
                            
                            if ($sRow['reservation_detail_lname'] != "" && $sRow['reservation_detail_lname'] != '-') {
                                $lname = $sRow['reservation_detail_lname'];
                            }

                            //กรณีจอง
                            if ($sRow['reservation_status'] == '0') {
                                $Room = "<font size=\"3\"><b>" . $rRow['room_name'] . "</b></font><br>จอง<br>" . $sRow['reservation_detail_fname'] . " " . $lname . "<br>" . $phone;
                                $rClass = "rReservation";
                            }
                            //กรณีจอง cf แล้ว
                            if ($sRow['reservation_status'] == '1') {
                                $Room = "<font size=\"3\"><b>" . $rRow['room_name'] . "</b></font><br>จอง มัดจำแล้ว<br>" . $sRow['reservation_detail_fname'] . " " . $lname . "<br>" . $phone;
                                $rClass = "rReservation1";
                            }
                            //กรณี เข้าอยู่แล้ว
                            if ($sRow['reservation_status'] == '2') {
                                $Room = "<font size=\"3\"><b>" . $rRow['room_name'] . "</b></font><br>ไม่ว่าง<br>" . $sRow['reservation_detail_fname'] . " " . $lname . "<br>" . $phone;
                                $rClass = "rReservation2";
                            }
                        } else {
                            $Room = "<font size=\"3\"><b>" . $rRow['room_name'] . "</b></font><br>ว่าง<input type=\"checkbox\" name=\"rCheck[]\" id=\"rCheck_" . $rRow['room_id'] . "\" value=\"$roomid#$day\"/>";
                            $rClass = "nReservation";
                        }
                        ?>
                        <li <?php if ($rClass != 'rReservation2') { ?>OnMouseOver="this.className='overmouse'" onmouseout="this.className='<?php echo $rClass; ?>'" onclick="rCheckBox('rCheck_<?php echo $rRow['room_id']; ?>','lCheck_<?php echo $rRow['room_id']; ?>','<?php echo $rClass; ?>');" <?php } ?> class="<?php echo $rClass; ?>"><?php echo $Room; ?></li>
                        <?php
                    }
                    ?>
                </ul>
                <div class="clr"></div>

                <!-- แสดงรายชื่อผู้ที่จ้องห้องพัก -->
                <?php
                $rQuery = mysql_query("SELECT reservation_detail.reservation_detail_id as reservation_detail_id,reservation_detail.reservation_detail_fname as reservation_detail_fname,reservation_detail.reservation_detail_lname as reservation_detail_lname,reservation_detail.reservation_detail_payment_information as reservation_detail_payment_information FROM reservation_detail,reservation WHERE reservation_detail.reservation_detail_id=reservation.reservation_detail_id AND reservation.reservation_status='0' AND reservation.reservation_checkin = '$day' GROUP BY reservation.reservation_detail_id");
                ?>
                <table class="listshow" style="margin-top: 30px;">
                    <thead style="font-weight: bold;">
                        <tr>
                            <td class="center">ลำดับ</td>
                            <td class="center">ชื่อ-นามสกุล</td>
                            <td class="center">รายละเอียด</td>
                            <td class="center">เลือก</td>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $num = 0;
                        while ($rRow = mysql_fetch_array($rQuery)) {
                            //$TotalQuery = mysql_query("SELECT reservation_detail_total FROM reservation_detail WHERE reservation_detail_id = '".$rRow['reservation_detail_id']."' ");
                            //$TotalRow = mysql_fetch_array($TotalQuery);
                            $num++;
                            $rlname = '';
                            if ($rRow['reservation_detail_lname'] != "" && $rRow['reservation_detail_lname'] != '-') {
                                $rlname = $rRow['reservation_detail_lname'];
                            }
                            ?>
                            <tr>
                                <td width="80px" class="center"><?php echo $num; ?></td>
                                <td class="left" style="padding-left: 20px;"><?php echo $rRow['reservation_detail_fname'] . ' ' . $rlname . ' (' . $rRow['reservation_detail_payment_information'] . ')'; ?></td>
                                <td class="left">
                                    <table class="list3">
                                    <?php
                                    $sQuery = mysql_query("SELECT reservation_checkin FROM reservation WHERE reservation_detail_id = '" . $rRow['reservation_detail_id'] . "' GROUP BY reservation_checkin ORDER BY reservation_checkin");
                                    while ($sRow = mysql_fetch_array($sQuery)) {
                                        $dQuery = mysql_query("SELECT room.room_name as room_name,room.room_pax as room_pax FROM reservation,room WHERE room.room_id = reservation.room_id AND reservation.reservation_checkin = '" . $sRow['reservation_checkin'] . "' AND reservation.reservation_detail_id = '" . $rRow['reservation_detail_id'] . "' ");
                                        $roomNum = 0;
                                        ?>
                                        
                                            <?php
                                            while ($dRow = mysql_fetch_array($dQuery)) {
                                                $roomNum++;
                                                $room_name .= ", " . $dRow['room_name'];
                                                //$Room_Pax = $Room_Pax + $dRow['room_pax'];
                                            }
                                            ?>
                                            <tr>
                                                <td><?php echo ThaiDate2(strtotime($sRow['reservation_checkin'])); ?></td>
                                                <td><?php echo "<b> (" . $roomNum . " ห้อง)</b> " . substr($room_name, 2); ?></td>
                                            </tr>
                                            <?php
                                            $room_name = "";
                                        }
                                        ?>
                                    </table>
                                </td>
                                <td class="center"><img src="../image/Log-Out-icon.png" alt="Check In" style="cursor: pointer;" onclick="window.location.href='abc.php?id=<?php echo $rRow['reservation_detail_id'];?>'" title="Check In"/></td>
                            </tr>
                            <?php
                        }
                        ?>
                    </tbody>
                </table>
                <!-- จบ แสดงรายชื่อผู้ที่จ้องห้องพัก -->
            </div>
        </div>
    </form>
</body>
<?php include('footer.php'); ?>
